import ajax from '@/uni_modules/u-ajax/js_sdk'

const instance = ajax.create({
	baseURL: '/',
})

// 添加请求拦截器
instance.interceptors.request.use(
	config => {
		console.log(config, 'config')
		return config
	},
	error => {
		return Promise.reject(error)
	}
)

// 添加响应拦截器
instance.interceptors.response.use(
	response => {
		console.log(response, 'response')
		return response.data
	},
	error => {
		return Promise.reject(error)
	}
)


const requrst = ({
	method = 'GET',
	url,
	data = {},
	header
}) => {
	const config = {
		url,
		method,
		data
	}
	if (header) {
		config.header = header
	}
	return instance(config)
}


export default requrst;
